package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.entity.AirGridMemberTrajectorySettingEntity;
import com.iwomy.envpro.platform.service.AirGridMemberTrajectorySettingService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 空气网格成员轨迹设置表
 *
 * @author pig
 * @date 2023-08-26 11:48:46
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/airGridMemberTrajectorySetting" )
@Tag(description = "airGridMemberTrajectorySetting" , name = "空气网格成员轨迹设置表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AirGridMemberTrajectorySettingController {

    private final  AirGridMemberTrajectorySettingService airGridMemberTrajectorySettingService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param airGridMemberTrajectorySetting 空气网格成员轨迹设置表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_airGridMemberTrajectorySetting_view')" )
    public R getAirGridMemberTrajectorySettingPage(@ParameterObject Page page,@ParameterObject AirGridMemberTrajectorySettingEntity airGridMemberTrajectorySetting) {
        LambdaQueryWrapper<AirGridMemberTrajectorySettingEntity> wrapper = Wrappers.lambdaQuery(airGridMemberTrajectorySetting);
        return R.ok(airGridMemberTrajectorySettingService.page(page, wrapper));
    }


    /**
     * 通过id查询空气网格成员轨迹设置表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platform_airGridMemberTrajectorySetting_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(airGridMemberTrajectorySettingService.getById(id));
    }

    /**
     * 新增空气网格成员轨迹设置表
     * @param airGridMemberTrajectorySetting 空气网格成员轨迹设置表
     * @return R
     */
    @Operation(summary = "新增空气网格成员轨迹设置表" , description = "新增空气网格成员轨迹设置表" )
    @SysLog("新增空气网格成员轨迹设置表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_airGridMemberTrajectorySetting_add')" )
    public R save(@RequestBody AirGridMemberTrajectorySettingEntity airGridMemberTrajectorySetting) {
        return R.ok(airGridMemberTrajectorySettingService.save(airGridMemberTrajectorySetting));
    }

    /**
     * 修改空气网格成员轨迹设置表
     * @param airGridMemberTrajectorySetting 空气网格成员轨迹设置表
     * @return R
     */
    @Operation(summary = "修改空气网格成员轨迹设置表" , description = "修改空气网格成员轨迹设置表" )
    @SysLog("修改空气网格成员轨迹设置表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_airGridMemberTrajectorySetting_edit')" )
    public R updateById(@RequestBody AirGridMemberTrajectorySettingEntity airGridMemberTrajectorySetting) {
        return R.ok(airGridMemberTrajectorySettingService.updateById(airGridMemberTrajectorySetting));
    }

    /**
     * 通过id删除空气网格成员轨迹设置表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除空气网格成员轨迹设置表" , description = "通过id删除空气网格成员轨迹设置表" )
    @SysLog("通过id删除空气网格成员轨迹设置表" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_airGridMemberTrajectorySetting_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(airGridMemberTrajectorySettingService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param airGridMemberTrajectorySetting 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_airGridMemberTrajectorySetting_export')" )
    public List<AirGridMemberTrajectorySettingEntity> export(AirGridMemberTrajectorySettingEntity airGridMemberTrajectorySetting) {
        return airGridMemberTrajectorySettingService.list(Wrappers.query(airGridMemberTrajectorySetting));
    }
}